﻿Imports Heren.Common.Forms.Editor
Imports Heren.Common.Forms
Imports Heren.Common.ScriptEngine.Script
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports Heren.Common.Forms.Runtime
Imports System.Text
Imports Heren.Common.Libraries

Public Class 坠床跌倒事件报告单 : Inherits AbstractRuntimeHandler
    ''*********************************************************************************
    '' 这是护理电子病历表单后台运行支持脚本
    '' 注意：这是Visual Basic脚本，您可以不区分大小写 
    '' Script Language : Visual Basic
    '' Author : YangMingkun, Date : 2012-3-18
    '' Copyright (C) Heren Health Services (SUPCON) Co.,Ltd.
    ''*********************************************************************************


    '这一行是类定义,建议您最好改一下类的名称以免重复,不过重复也没关系
    '但当前脚本文件内,如果定义了多个Class,那么名称就不要重复了,以免无法编译通过


    '当系统加载完毕护理表单时调用此方法
    Public Overrides Sub initialize()
        Dim value As Object = Nothing

        Me.getSystemContext("创建人", value)



        Me.SetControltext("XTextBox11", value)



        Me.GetSystemContext("病历状态", value)
        If (value IsNot Nothing) Then
            '       shOWmESSAGE("病历状态：" +value.toString())
        End If
        If value = "新建" Then
            Me.RefreshPatientInfo()
        End If
        Me.SubmitBtnTextControl()
        'Me.ShowMessage("表单已完成加载!")
        '    Me.RegisterEvent("XTextBox48", "DoubleClick", "XTextBox48_DoubleClick")
        '    Me.RegisterEvent("XTextBox46", "DoubleClick", "XTextBox46_DoubleClick")
        '     Me.RegisterEvent("XTextBox47", "DoubleClick", "XTextBox47_DoubleClick")
        '      Me.RegisterEvent("XRadioButton2", "CheckedChanged", "XRadioButton2_CheckedChanged")

    End Sub


    Private Sub RefreshPatientInfo()
        Dim value As Object = Nothing
        Me.GetSystemContext("病人姓名", value)
        ''        shOWmESSAGE("病人姓名：" +value.toString())
        Me.SetControlText("XTextBox17", value)

        Me.GetSystemContext("病人性别", value)
        Me.SetControlText("XTextBox2", value)


        Me.GetSystemContext("就诊科室名称", value)
        Me.SetControlText("XTextBox19", value)


        Me.GetSystemContext("床号", value)
        Me.SetControlText("XTextBox18", value)

        Me.GetSystemContext("住院号", value)
        Me.SetControlText("XTextBox8", value)

        Me.GetSystemContext("病人年龄", value)
        Me.SetControlText("XTextBox3", value)

        ' dim ruyuantime As string =  Me.GetSystemContext("入院时间", value)
        ' shOWmESSAGE("入院时间：" + ruyuantime)
        '    Me.SetControlText("XTextBox4", ruyuantime)

        Dim userName As String = ""
        Me.GetSystemContext("用户姓名", userName)
        Me.SetControlText("XTextBox5", userName)
        Dim pid As String = ""
        Me.GetSystemContext("病人ID号", pid)

        Dim vid As String = ""
        Me.GetSystemContext("入院次", vid)



        Dim sql As New StringBuilder
        sql.AppendFormat("select marital_status from pat_visit@link_emr where patient_id='{0}' and visit_id='{1}'", pid, vid)
        Dim data As DataSet = Nothing
        If Me.executequery(sql.ToString(), data) Then
            Me.SetControlText("XComboBox1", Me.GetFieldValue(data, 0, 0))
            '           Me.SetControlText("XTextBox10", me.GetFieldValue(data, 0, 1))  
            '            Me.SetControlText("XTextBox11", me.GetFieldValue(data, 0, 2))
            '              Me.SetControlText("XTextBox37", me.GetFieldValue(data, 0, 3))
            '             Me.SetControlText("XTextBox15", me.GetFieldValue(data, 0, 4))
        End If

        '          


        sql = New StringBuilder
        sql.AppendFormat("select  a.nation from  pat_master_index@link_emr  a  where   patient_id='{0}'", pid)
        data = Nothing
        If Me.executequery(sql.ToString(), data) Then
            Me.SetControlText("XComboBox5", Me.GetFieldValue(data, 0, 0))

        End If

        '        

        sql = New StringBuilder
        sql.AppendFormat("select record_name,record_time from vital_signs_v where record_name= '入院' and patient_id='{0}' and visit_id='{1}' order by record_time", pid, vid)
        data = Nothing
        'showmessage(sql.tostring())
        If Me.executequery(sql.ToString(), data) Then

            Me.SetControlText("XTextBox4", Me.GetFieldValue(data, 0, 1))

        End If



        sql = New StringBuilder
        sql.AppendFormat("select diagnosis from pats_in_hospital@link_emr where patient_id='{0}' and visit_id='{1}'", pid, vid)
        data = Nothing
        If Me.executequery(sql.ToString(), data) Then
            Me.SetControlText("XTextBox9", Me.GetFieldValue(data, 0, 0))
        End If
    End Sub






    ''当用户在界面上请求获取表单摘要数据时调用此方法
    'Public  Function GenerateSummary() As String
    '    Dim strSummary As New StringBuilder
    '    Dim control As Control = Me.FindControl("XTextBox1")
    ''    If control IsNot Nothing Then
    ''       strSummary.Append("姓名="+ control.Text)
    ''    End If
    ''    
    ''    control = Me.FindControl("XTextBox2")
    ''    If control IsNot Nothing Then
    ''       strSummary.Append("性别="+ control.Text)
    ''    End If
    '    
    ''      control = Me.FindControl("XTextBox6")
    ''    If control IsNot Nothing Then
    ''       strSummary.Append("科室="+ control.Text)
    ''    End If
    ''    
    ''      control = Me.FindControl("XTextBox8")
    ''    If control IsNot Nothing Then
    ''       strSummary.Append("住院号="+ control.Text)
    ''    End If
    '   
    ''     control = Me.FindControl("XTextBox7")
    ''    If control IsNot Nothing Then
    ''       strSummary.Append("床号="+ control.Text)
    ''    End If
    ''    
    ''    control = Me.FindControl("XTextBox3")
    ''    If control IsNot Nothing Then
    ''       strSummary.Append("年龄="+ control.Text)
    ''    End If
    '    
    '    Return strSummary.ToString()
    'End Function



    '获取关键数据列表
    Public Overrides Function GetKeyDataList() As List(Of KeyData)

        Dim keyDataList As New List(Of KeyData)
        Dim shenqing As XDateTime = CType(Me.FindControl("XDateTime3"), XDateTime)

        '科室
        Dim pat_dept As XTextBox = Me.FindControl("XTextBox19")
        If pat_dept.Text <> "" Then
            keyDataList.Add(New KeyData("病人科室", pat_dept.Text))
        End If
        '床号
        Dim pat_bed As XTextBox = Me.FindControl("XTextBox18")
        If pat_bed.Text <> "" Then
            keyDataList.Add(New KeyData("病人床号", pat_bed.Text))
        End If
        '住院号
        Dim pat_inp As XTextBox = Me.FindControl("XTextBox8")
        If pat_inp.Text <> "" Then
            keyDataList.Add(New KeyData("病人住院号", pat_inp.Text))
        End If
        '姓名
        Dim pat_name As XTextBox = Me.FindControl("XTextBox17")
        If pat_name.Text <> "" Then
            keyDataList.Add(New KeyData("病人姓名", pat_name.Text))
        End If
        '诊断
        Dim pat_dis As XTextBox = Me.FindControl("XTextBox9")
        If pat_dis.Text <> "" Then
            keyDataList.Add(New KeyData("病人诊断", pat_dis.Text))
        End If

        '申报人
        Dim shenqing1 As XTextBox = Me.FindControl("XTextBox11")
        If shenqing1.Text <> "" Then
            keyDataList.Add(New KeyData("申请时间", shenqing.Value))
        End If

        Dim hushizhang As XTextBox = Me.FindControl("XTextBox13")
        If hushizhang IsNot Nothing Then
            keyDataList.Add(New KeyData("护士长", hushizhang.Text))
        End If
        '    Dim hushizhangshenhe As XDateTime = CType(Me.FindControl("XDateTime1"),XDateTime)
        Dim hushizhangshenhe As Date = Date.MinValue 'date.Parse(Me.GetControlText("XTextBox1")）
        If Me.GetControlText("XTextBox1") <> "" Then
            hushizhangshenhe = Date.Parse(Me.GetControlText("XTextBox16"))
            '    	hushizhangshenhe=Me.GetControlText("XTextBox1")
        End If
        Dim hushizhang1 As XTextBox = Me.FindControl("XTextBox13")
        If hushizhang1.Text <> "" Then
            keyDataList.Add(New KeyData("护士长审核时间", hushizhangshenhe))
        End If
        Dim hulibu As XTextBox = Me.FindControl("XTextBox6")
        If hulibu IsNot Nothing Then
            keyDataList.Add(New KeyData("护理部审核人", hulibu.Text))
        End If


        '    Dim hulibushenhe As XDateTime = CType(Me.FindControl("XDateTime2"),XDateTime)
        Dim hulibushenhe As Date = Date.MinValue 'date.Parse(Me.GetControlText("XTextBox11")）
        If Me.GetControlText("XTextBox1") <> "" Then
            hulibushenhe = Date.Parse(Me.GetControlText("XTextBox1"))
        End If
        Dim hulibu2 As XTextBox = Me.FindControl("XTextBox6")
        If hulibu2.Text <> "" Then
            keyDataList.Add(New KeyData("护理部审核时间", hulibushenhe))
        End If


        '不良事件上报统计报表需要的数据
        keyDataList.Add(New KeyData("ReportType", "跌倒/坠床"))
        '是否发生医疗医疗争议
        If IsRadioButtonChecked("XRadioButton14") Then
            keyDataList.Add(New KeyData("是否发生医疗医疗争议", Me.GetRadioButtonTag("XRadioButton14")))
        ElseIf IsRadioButtonChecked("XRadioButton15") Then
            keyDataList.Add(New KeyData("是否发生医疗医疗争议", Me.GetRadioButtonTag("XRadioButton15")))
        ElseIf IsRadioButtonChecked("XRadioButton16") Then
            keyDataList.Add(New KeyData("是否发生医疗医疗争议", Me.GetRadioButtonTag("XRadioButton16")))
        ElseIf IsRadioButtonChecked("XRadioButton24") Then
            keyDataList.Add(New KeyData("是否发生医疗医疗争议", Me.GetRadioButtonTag("XRadioButton24")))
        End If


        Return keyDataList
    End Function


    Private b_submit As Boolean = False
    Private b_return As Boolean = False
    '获取表单中指定的数据
    Public Overrides Function GetFormData(ByVal param As Object) As Object
        If param = "是否显示按钮1" Then
            Return b_submit
        End If
        If param = "是否显示按钮2" Then
            Return b_return
        End If

        '去除24小时不可修订的权限控制2013-5-2
        If param = "表单权限" Then
            Return True
        End If

    End Function


    '得到单选框的tag值
    Private Function GetRadioButtonTag(ByVal controlName As String) As String
        Dim control As Control = Me.findControl(controlName)
        If control Is Nothing Then
            Return String.Empty
        End If
        Return control.Tag
    End Function

    '保存
    Public Overrides Function SaveFormData(ByRef param As Object) As Boolean
        If param = "提交" Then
            Me.SubMitInfo()
        ElseIf param = "审核提交" Then
            Me.SubMitInfo()
        ElseIf param = "转归提交" Then
            Me.SubMitInfo()
        ElseIf param = "接收" Then
            Me.SubMitInfo()
        ElseIf param = "驳回" Then
            Me.RetrunInfo()
        End If
        '  showmessage(b_submit.tostring() & "/" & b_return.tostring())
        Me.RaiseCustomEvent("sender", "按钮1可见", b_submit, Nothing, Nothing)
        Me.RaiseCustomEvent("sender", "按钮2可见", b_return, Nothing, Nothing)
        Return True
    End Function




    Private Sub RetrunInfo()
        Me.RaiseCustomEvent("sender", "保存", Nothing, Nothing, Nothing)
        '根据申报单状态读写申报单申请信息
        Dim strPatientId As String = ""
        Me.GetSystemContext("病人ID号", strPatientId)
        Dim strVisitId As String = ""
        Me.GetSystemContext("入院次", strVisitId)

        '先读取申报单本身信息
        Dim strDocSetId As String = ""
        Me.GetSystemContext("文档集编号", strDocSetId)
        If strDocSetId = "" Then
            ShowMessage("请先保存压疮申报单！")
            Return
        End If

        '再读申报单对应的申请信息
        Dim applyData As DataSet = GetApplyByDocSetId(strDocSetId)
        If applyData Is Nothing OrElse applyData.Tables.Count <= 0 OrElse applyData.Tables(0).Rows.Count <= 0 Then
            Return
        End If
        '驳回理由
        Dim strStateMessage As String = ""
        If Not Me.ShowChildForm("230745", "tag", strStateMessage) Then
            Return
        End If
        '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
        '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
        Dim strStatus As String = Me.GetFieldValue(applyData, 0, 3)
        Dim strApplyId As String = Me.GetFieldValue(applyData, 0, "apply_id")
        Select Case strStatus
            Case "2"
                '处理护士长驳回
                Me.SubmitProcess("sender", strApplyId, "7", "驳回", strStateMessage, "是否进行驳回？", "驳回确认")
            Case "4"
                '护理部驳回
                If Me.GetReportType() = 2 Then
                    Me.SubmitProcess("sender", strApplyId, "8", "驳回", strStateMessage, "是否进行驳回？", "驳回确认")
                Else
                    Me.SubmitProcess("sender", strApplyId, "9", "驳回", strStateMessage, "是否进行驳回？", "驳回确认")
                End If
            Case "8"
                Me.SubmitProcess("sender", strApplyId, "7", "驳回", strStateMessage, "是否进行驳回？", "驳回确认")
        End Select
    End Sub
    '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
    '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
    Private Sub SubmitProcess(ByVal sender As System.Object, ByVal strApplyId As String, ByVal strState As String, ByVal strStatusDesc As String, ByVal strStatusMessage As String, ByVal strMessage As String, ByVal strMessageTitle As String)
        Dim Response As Object = MsgBox(strMessage, vbYesNo, strMessageTitle)
        If Response = vbYes Then   ' 用户按下“是”。
            Me.SaveApply("sender", False, strApplyId, "坠床跌倒申报", "0", "", "", "", "", strState, strStatusDesc, strStatusMessage)
            Me.SubmitBtnTextControl()
            If strState = "2" Then '护士长接收自动填写
                Dim userName As String = ""
                Me.GetSystemContext("用户姓名", userName)
                Me.SetControlText("XTextBox13", userName)
                Dim time As Date = Date.Now
                Dim XTextBox1 As XTextBox = Me.FindControl("XTextBox16")
                XTextBox1.Text = time.ToString()
            ElseIf strState = "4" Then '护理部接收自动填写
                Dim userName As String = ""
                Me.GetSystemContext("用户姓名", userName)
                Me.SetControlText("XTextBox6", userName)
                Dim time As Date = Date.Now
                Dim XTextBox11 As XTextBox = Me.FindControl("XTextBox1")
                XTextBox11.Text = time.ToString()
            End If

            If strState = "7" Then
                Me.SetControlText("XTextBox13", "")
                Me.SetControlText("XTextBox16", "")
            ElseIf strState = "8" OrElse strState = "9" Then
                Me.SetControlText("XTextBox6", "")
                Me.SetControlText("XTextBox1", "")
            End If
            '      Me.RaiseCustomEvent("sender", "保存", nothing, nothing, nothing)
        End If
        Me.RaiseCustomEvent("sender", "保存", Nothing, Nothing, Nothing)
    End Sub


    Private Sub SubmitBtnTextControl()

        Dim strPatientId As String = ""
        Me.GetSystemContext("病人ID号", strPatientId)
        Dim strVisitId As String = ""
        Me.GetSystemContext("入院次", strVisitId)
        Dim strUserId As Object = ""
        Me.GetSystemContext("用户编号", strUserId)
        '权限设定
        Dim UserPermiss As String = ""
        Me.GetSystemContext("用户权限_主管护师", UserPermiss)
        Dim bzhuguan As Boolean = UserPermiss = "True"
        Me.GetSystemContext("用户权限_主任护师", UserPermiss)
        Dim bzhuren As Boolean = UserPermiss = "True"
        Me.GetSystemContext("用户权限_护理部", UserPermiss)
        Dim bHuli As Boolean = UserPermiss = "True"

        b_submit = True
        Me.RaiseCustomEvent("sender", "按钮1可见", b_submit, Nothing, Nothing)
        Me.RaiseCustomEvent("sender", "按钮2可见", b_return, Nothing, Nothing)

        Me.RaiseCustomEvent("sender", "按钮1名称", "提交", Nothing, Nothing)
        Dim XGroupBox1 As XGroupBox = CType(Me.Findcontrol("XGroupBox1"), XGroupBox)
        Dim XGroupBox2 As XGroupBox = CType(Me.Findcontrol("XGroupBox2"), XGroupBox)
        Dim XGroupBox3 As XGroupBox = CType(Me.Findcontrol("XGroupBox3"), XGroupBox)

        '先读取申报单本身信息
        Dim strDocSetId As String = ""
        Me.GetSystemContext("文档集编号", strDocSetId)

        If strDocSetId = "" Then
            Return
        End If
        '再读申报单对应的申请信息
        Dim applyData As DataSet = Me.GetApplyByDocSetId(strDocSetId)
        If applyData Is Nothing OrElse applyData.Tables.Count <= 0 OrElse applyData.Tables(0).Rows.Count <= 0 Then
            PanelEnableControl(True)
            Return
        End If

        '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
        '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
        Dim strStatus As String = Me.GetFieldValue(applyData, 0, 3)
        Dim strApplyId As String = Me.GetFieldValue(applyData, 0, "apply_id")
        Dim strOperatorId As String = Me.GetFieldValue(applyData, 0, "operator_id")
        Dim strApplicantId As String = Me.GetFieldValue(applyData, 0, "applicant_id")

        Select Case strStatus
            Case "1"
                PanelEnableControl(False)
                XGroupBox2.Enabled = False
                XGroupBox3.Enabled = False
                Me.RaiseCustomEvent("sender", "按钮1名称", "接收", Nothing, Nothing)
                '    If strOperatorId=strUserId Then
                ''    showmessage(strOperatorId &"=" & strUserId)
                '       b_submit=false
                '       b_return=false
                '    Else
                '      if bzhuguan orelse bzhuren then
                '       b_submit=true
                '      else
                '       b_submit=false
                '      end if
                '    End If
                If bzhuguan OrElse bzhuren Then
                    b_submit = True
                Else
                    b_submit = False
                End If


            Case "2"
                PanelEnableControl(False)
                XGroupBox2.Enabled = False
                XGroupBox3.Enabled = False

                If strOperatorId = strUserId Then
                    Me.RaiseCustomEvent("sender", "按钮1名称", "审核提交", Nothing, Nothing)
                    Me.RaiseCustomEvent("sender", "按钮2名称", "驳回", Nothing, Nothing)
                    b_return = True
                    b_submit = True
                    XGroupBox2.Enabled = True
                Else
                    b_submit = False
                End If

            Case "3"
                PanelEnableControl(False)
                XGroupBox2.Enabled = False
                XGroupBox3.Enabled = False
                If strOperatorId = strUserId Then
                    b_submit = False
                    b_return = False
                Else
                    If bHuli Then
                        b_submit = True
                    Else
                        b_submit = False
                    End If
                End If
                Me.RaiseCustomEvent("sender", "按钮1名称", "接收", Nothing, Nothing)

            Case "4"
                PanelEnableControl(False)
                XGroupBox2.Enabled = False

                XGroupBox3.Enabled = False
                If strOperatorId = strUserId Then
                    Me.RaiseCustomEvent("sender", "按钮1名称", "审核提交", Nothing, Nothing)
                    Me.RaiseCustomEvent("sender", "按钮2名称", "驳回", Nothing, Nothing)
                    b_return = True
                    XGroupBox3.Enabled = True
                Else
                    b_submit = False
                End If

                '   Case "5"
                '     PanelEnableControl(false)
                '     XGroupBox3.Enabled=true
                '     XGroupBox5.Enabled=false
                '     XGroupBox6.Enabled=false
                '     XGroupBox7.Enabled=true
                '     Me.RaiseCustomEvent("sender","按钮1名称","转归提交",nothing,nothing)
                '     b_return=false

                '   Case "6"
                '     PanelEnableControl(false)
                '    XGroupBox5.Enabled=false
                '    XGroupBox6.Enabled=false
                '    XGroupBox3.Enabled=false
                '    b_submit=false

            Case "7", "9"
                PanelEnableControl(False)
                XGroupBox2.Enabled = False

                XGroupBox3.Enabled = False
                Me.RaiseCustomEvent("sender", "按钮1名称", "提交", Nothing, Nothing)
                If strApplicantId <> strUserId Then
                    b_submit = False
                    b_return = False
                Else
                    b_submit = True
                    PanelEnableControl(True)
                End If

            Case "8"
                '获取上次审核提交操作人
                PanelEnableControl(False)
                XGroupBox2.Enabled = False

                XGroupBox3.Enabled = False
                Dim strLastCheckedId As String = Me.GetFieldValue(applyData, 0, "operator_id")
                Me.RaiseCustomEvent("sender", "按钮1名称", "审核提交", Nothing, Nothing)
                Me.RaiseCustomEvent("sender", "按钮2名称", "驳回", Nothing, Nothing)
                If strLastCheckedId <> strUserId Then
                    If bzhuguan OrElse bzhuren Then
                        b_submit = True
                        b_return = True
                        XGroupBox2.Enabled = True
                    Else
                        b_submit = False
                        b_return = False
                    End If
                Else
                    b_submit = False
                    b_return = False
                End If
        End Select
        '    showmessage(b_submit.tostring() & "?" & b_return.tostring())
        Me.RaiseCustomEvent("sender", "按钮1可见", b_submit, Nothing, Nothing)
        Me.RaiseCustomEvent("sender", "按钮2可见", b_return, Nothing, Nothing)
    End Sub


    Private Sub PanelEnableControl(ByVal bEnabled As Boolean)
        Dim XGroupBox1 As XGroupBox = CType(Me.Findcontrol("XGroupBox1"), XGroupBox)

        Dim XGroupBox2 As XGroupBox = CType(Me.Findcontrol("XGroupBox2"), XGroupBox)

        Dim XGroupBox3 As XGroupBox = CType(Me.Findcontrol("XGroupBox3"), XGroupBox)
        XGroupBox1.Enabled = bEnabled


        If bEnabled = True Then
            XGroupBox2.Enabled = False
            XGroupBox3.Enabled = False
        Else
            XGroupBox2.Enabled = True
            XGroupBox3.Enabled = True
        End If

    End Sub

    Private Function GetApplyByDocSetId(ByVal strDocSetId As String) As DataSet
        Dim applySql As New StringBuilder
        applySql.Append("select apply_type,apply_name,urgency,nur_apply_index.status,patient_id,")
        applySql.Append(" patient_name,visit_id,sub_id,ward_code,ward_name,")
        applySql.Append(" applicant_id,applicant_name,apply_time,modifier_id,")
        applySql.Append(" modifier_name,modify_time,operator_id,operator_name,")
        applySql.Append(" operate_time,status_desc,next_operator_id,")
        applySql.Append(" next_operator_name,next_operator_ward_code,next_operator_ward_name,nur_apply_index.apply_id")
        applySql.Append(" from nur_apply_index join nur_apply_status ")
        applySql.Append(" on nur_apply_index.apply_id= nur_apply_status.apply_id ")
        applySql.Append(" and nur_apply_index.status= nur_apply_status.status ")
        applySql.AppendFormat(" where nur_apply_index.doc_id='{0}' order by nur_apply_status.operate_time desc ", strDocSetId)
        Dim data As DataSet = Nothing
        Me.ExecuteQuery(applySql.ToString(), data)
        Return data
    End Function

    Private Sub SaveApply(ByVal sender As System.Object, ByVal bIsNew As Boolean, ByVal strApplyID As String, ByVal strApplyType As String, ByVal strUrgency As String, ByVal strNextOperatorID As String, ByVal strNextOperatorName As String, ByVal strNextOperatorWardCode As String, ByVal strNextOperatorWardName As String, ByVal strState As String, ByVal strStatusDesc As String, ByVal strStatusMessage As String)
        '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
        '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
        '接口对接参数不允许删除
        '--------------------------------------
        Dim szApplyID As String = strApplyID
        Dim szApplyType As String = strApplyType
        Dim szUrgency As String = strUrgency
        Dim szNextOperatorID As String = strNextOperatorID
        Dim szNextOperatorName As String = strNextOperatorName
        Dim szNextOperatorWardCode As String = strNextOperatorWardCode
        Dim szNextOperatorWardName As String = strNextOperatorWardName
        Dim szStatus As String = strState
        Dim szStatusDesc As String = strStatusDesc
        Dim szStatusMessage As String = strStatusMessage
        '--------------------------------------
        Dim strData As String = ""
        strData = szApplyID + ";" + szApplyType + ";" + szUrgency + ";" + szNextOperatorID + ";" + szNextOperatorName + ";" + szNextOperatorWardCode + ";" + szNextOperatorWardName + ";" + szStatus + ";" + szStatusDesc + ";" + szStatusMessage
        If bIsNew Then
            Me.RaiseCustomEvent(sender, "保存护理申请信息", Nothing, strData, Nothing)
        Else
            Me.RaiseCustomEvent(sender, "更新护理申请信息", Nothing, strData, Nothing)
        End If
    End Sub

    Private Function GetReportType() As Integer
        Dim returnValue As Integer = 2
        '  '返回1表示直接护理部审批，返回2表示需要先走护士长审批，然后再走护理部审批
        '   Dim radioButton As Control= Me.GetCheckedButton("XGroupBox8")
        '   Dim strReportType As String=""
        '   If radioButton IsNot Nothing AndAlso CType(radioButton,XRadioButton) IsNot Nothing Then
        '      strReportType=CType(radioButton,XRadioButton).Text
        '   End If
        '   Dim XCheckBox1 As XCheckBox=CType(Me.Findcontrol("XCheckBox1"), XCheckBox)
        '   Dim XCheckBox4 As XCheckBox=CType(Me.Findcontrol("XCheckBox4"), XCheckBox)
        ''   showmessage(strReportType)
        '   If strReportType="院外带入压疮" OrElse strReportType="高危备案" OrElse XCheckBox1.checked=true OrElse XCheckBox1.checked=true Then
        '      returnValue= 2
        '   Else 
        '      returnValue= 1
        '   End If
        Return returnValue
    End Function

    Private Sub SubMitInfo()
        If Not CheckForm() Then
            Return
        End If
        Me.RaiseCustomEvent("sender", "保存", Nothing, Nothing, Nothing)
        '根据申报单状态读写申报单申请信息
        Dim strPatientId As String = ""
        Me.GetSystemContext("病人ID号", strPatientId)
        Dim strVisitId As String = ""
        Me.GetSystemContext("入院次", strVisitId)

        '先读取申报单本身信息
        Dim strDocSetId As String = ""
        Me.GetSystemContext("文档集编号", strDocSetId)
        If strDocSetId = "" Then
            ShowMessage("请先保存压疮申报单！")
            Return
        End If

        '再读申报单对应的申请信息
        Dim applyData As DataSet = GetApplyByDocSetId(strDocSetId)
        If applyData Is Nothing OrElse applyData.Tables.Count <= 0 OrElse applyData.Tables(0).Rows.Count <= 0 Then
            '新增申报单对应的申请信息,如果申报类型为“院外带入压疮”、“高危备案”则需要先走护士长审核，然后再到护理部审核；
            '如果申报类型为“院内发生压疮”、“申报不可避免压疮”则直接到护理部审核,所以状态为3,但状态显示为“已申报”

            If Me.GetReportType() = 2 Then
                Me.SaveApply("sender", True, "", "坠床跌倒申报", "0", "", "", "", "", "1", "已申报", "")
            Else
                Me.SaveApply("sender", True, "", "坠床跌倒申报", "0", "", "", "", "", "3", "已申报", "")
            End If
            Me.SubmitBtnTextControl()
            Return
        End If

        Me.SubmitBtnTextControl()
        '申报单申请状态说明：1表示已申报 2表示审核中 3表示已审核 4表示审批中 5表示已审批 6表示已转归 7表示护士长驳回 
        '8表示护理部驳回(护士长的审批) 9表示护理部驳回（“院内发生压疮”、“申报不可避免压疮”的直接申报）
        Dim strStatus As String = Me.GetFieldValue(applyData, 0, 3)
        Dim strApplyId As String = Me.GetFieldValue(applyData, 0, "apply_id")
        Select Case strStatus
            Case "1"
                '处理接收
                Me.SubmitProcess("sender", strApplyId, "2", "审核中", "", "是否进行接收操作？", "接收确认")
            Case "2"
                '处理审核
                Me.SubmitProcess("sender", strApplyId, "3", "已审核", "", "提交后不能修改，是否进行审核提交？", "审核确认")
            Case "3"
                '处理护理部接收
                Me.SubmitProcess("sender", strApplyId, "4", "审批中", "", "是否进行接收操作？", "接收确认")
            Case "4"
                '处理审批
                Me.SubmitProcess("sender", strApplyId, "5", "已审批", "", "是否进行审批提交？", "审批确认")
                '  Case "5"
                '      '处理转归
                '     Me.SubmitProcess("sender",strApplyId,"6","已转归","","是否进行转归提交？","转归确认")
                '  Case "6"
            Case "7"
                '处理重新申报
                Me.SubmitProcess("sender", strApplyId, "1", "已申报", "", "是否重新申报提交？", "提交确认")
            Case "8"
                '处理重新审核提交
                Me.SubmitProcess("sender", strApplyId, "3", "已审核", "", "是否重新审核提交？", "审核确认")
            Case "9"
                '处理重新提交
                Me.SubmitProcess("sender", strApplyId, "3", "已申报", "", "是否重新申报提交？", "提交确认")
        End Select
    End Sub


    Public Function CheckForm() As Boolean
        Dim message As New StringBuilder
        '申报类型
        If Not IsRadioButtonChecked("XRadioButton1") And Not IsRadioButtonChecked("XRadioButton2") _
        And Not IsRadioButtonChecked("XRadioButton3") And Not IsRadioButtonChecked("XRadioButton4") _
        And Not IsCheckButtonChecked("XRadioButton5") Then
            message.AppendLine("坠床/跌倒")
        End If
        '伤害结果
        If Not IsRadioButtonChecked("XRadioButton22") And Not IsRadioButtonChecked("XRadioButton23") Then
            message.AppendLine("伤害结果")
        End If
        '伤害等级

        If Not IsRadioButtonChecked("XRadioButton17") And Not IsRadioButtonChecked("XRadioButton18") _
        And Not IsRadioButtonChecked("XRadioButton19") And Not IsRadioButtonChecked("XRadioButton20") _
        And Not IsCheckButtonChecked("XRadioButton21") Then
            message.AppendLine("伤害等级")
        End If
        If Me.GetControlText("XTextBox10").trim() = "" Then
            message.AppendLine("事件经过和处理")
        End If

        If message.Length > 0 Then
            ShowWarning("以下选项：" & message.ToString() & "尚未填写内容！")
            Return False
        End If
        Return True
    End Function





    '-----------------------------------------------------------------------------------------------------------------------------------

    '压疮按钮2
    Private Sub XButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim table As String = ""
        Me.showchildForm("538234", "button2", table)
    End Sub

    '获取过敏数据区数据
    Private Function Get过敏() As String
        Dim strSummary As New StringBuilder

        Return strSummary.ToString()
    End Function

    Private Sub XButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.RefreshPatientInfo()
    End Sub


    '基本资料的 事件控件1
    Private Sub XTextBox15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim txt As XTextBox = CType(sender, XTextBox)

        Dim dtp As XDateTime = CType(Me.findcontrol("XDateTime3"), XDateTime)
        dtp.Focus()
        Dim time As Date = Date.Now
        dtp.Value = time.ToShortDateString()
        dtp.DroppedDown = True

    End Sub

    '基本资料的 事件控件2
    Private Sub XDateTime3_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)


        Dim dtp As XDateTime = CType(Me.findcontrol("XDateTime3"), XDateTime)
        Me.SetControlText("XTextBox15", dtp.Value.ToString("yyyy-MM-dd"))

    End Sub



    '科室意见 事件控件1
    Private Sub XTextBox16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim txt As XTextBox = CType(sender, XTextBox)

        Dim dtp As XDateTime = CType(Me.findcontrol("XDateTime4"), XDateTime)
        dtp.Focus()
        Dim time As Date = Date.Now
        dtp.Value = time.ToShortDateString()
        dtp.DroppedDown = True

    End Sub


    '科室意见 事件控件2
    Private Sub XDateTime4_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dtp As XDateTime = CType(Me.findcontrol("XDateTime4"), XDateTime)
        Me.SetControlText("XTextBox16", dtp.Value.ToString("yyyy-MM-dd"))
    End Sub


    '护理部意见 事件控件1
    Private Sub XTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim txt As XTextBox = CType(sender, XTextBox)

        Dim dtp As XDateTime = CType(Me.findcontrol("XDateTime5"), XDateTime)
        dtp.Focus()
        Dim time As Date = Date.Now
        dtp.Value = time.ToShortDateString()
        dtp.DroppedDown = True
    End Sub


    '护理部意见 事件控件2
    Private Sub XDateTime5_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dtp As XDateTime = CType(Me.findcontrol("XDateTime5"), XDateTime)
        Me.SetControlText("XTextBox1", dtp.Value.ToString("yyyy-MM-dd"))
    End Sub



End Class
